# -*- coding:utf8 -*-
import os
import re
import shutil
import cv2
import numpy as np
from PIL import Image


def norm_img(img):
    max_v = img.max()
    min_v = img.min()
    img = (img - min_v) / (max_v - min_v)
    return img * 255


file1 = './test1'
if not os.path.exists(file1):
    os.makedirs(file1)
path1 = './predict'
list_path = os.listdir(path1)

for i in range(len(list_path)):
    dicom_paths = os.path.join(path1, list_path[i])
    img_copy = cv2.imread(dicom_paths, cv2.IMREAD_ANYDEPTH)
    img_copy = norm_img(img_copy)
    prefix = str(i).zfill(5) + '.png'
    cv2.imwrite(os.path.join(file1, prefix), img_copy)